import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:jd_flutter/base/utils/jd_log.dart';
import 'package:jd_flutter/modules/pages/login/page/login_tool.dart';
import 'package:jd_flutter/modules/router/router_contract_page.dart';

import '../../config/app_init_config.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({Key? key}) : super(key: key);

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  @override
  void initState() {
    super.initState();

    kNetChangeNotifier.addListener(connectListener);

    jumpToOtherPage();
  }

  /// 设置网络切换监听
  connectListener() {
    ConnectivityResult result = kNetChangeNotifier.value;
    jdLog('网络状态变化了 -------  $result');
  }

  // 页面跳转
  jumpToOtherPage() {
    Future.delayed(const Duration(milliseconds: 100), () {
      if (LoginTool.isLogin()) {
        RouterContractPage.instance.tabNavigator
            .push(context, params: {}, hideAnimation: true, replacement: true);
      } else {
        RouterContractPage.instance.loginPage
            .push(context, params: {}, hideAnimation: true, replacement: true);
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return const SizedBox();
  }

  @override
  void dispose() {
    kNetChangeNotifier.removeListener(connectListener);
    super.dispose();
  }
}
